import logging


class Logger_handler(logging.Logger):
    def __init__(self, name, file, level,
                 format='%(filename)s-%(lineno)s-%(name)s-%(levelname)s-%(message)s'):
        # 初始化后收集器
        super(Logger_handler, self).__init__(name)
        self.setLevel(level)
        # 处理器
        fmt = logging.Formatter(format)
        if file:
            file_handler = logging.FileHandler(file)
            file_handler.setLevel(level)
            file_handler.setFormatter(fmt)
            self.addHandler(file_handler)
        #控制台输出
        stram_hand = logging.StreamHandler(file)
        stram_hand.setLevel(level)
        stram_hand.setFormatter(fmt)
        self.addHandler(stram_hand)
